<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      list-style: none;
    }

    .box {
      width: 500px;
      height: 300px;
      background-color: aqua;
    }

    .tit {
      width: 100%;
      height: 80px;
      display: flex;
      /* justify-content: space-around; */
      align-items: center;
    }

    .tit p {
      width: 50%;
    }

    .tit p:nth-child(1) {

      background-color: red;
    }

    .tit p:nth-child(2) {
      background-color: blue;
    }
  </style>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="root">
    <div class="box">
      <div class="tit">

        <p v-for="(v,index) in arr" :key='v.id' @click="Tab(index)"> {{v.name}} </p>

      </div>
      <div class="text" v-for="i in arr[type].children" :key='i.id'>
        {{i.name}}
      </div>
    </div>

  </div>
  <script>
    Vue.config.productionTip = false;
    new Vue({
      el: "#root",
      data: {
        type: 0,
        arr: [
          {
            id: 1,
            name: "社会新闻",
            children: [
              { id: 2, name: "油价上涨了" },
              { id: 3, name: "该核酸检测了" },
            ],
          },
          {
            id: 4,
            name: "娱乐新闻",
            children: [
              { id: 5, name: "周杰伦发歌了" },
              { id: 6, name: "周杰伦销量第一了" },
            ],
          },
        ],
      },
      methods: {
        Tab(num) {
          console.log(num);
          this.type = num
        }
      },
    });
  </script>
</body>

</html>